
package com.bootcamp.mall.model.vo.goods;

import com.bootcamp.mall.model.Spec;
import lombok.Data;

import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.List;
import java.util.Properties;

@Data
public class GoodsVO {
    private Integer id;
    private String img;
    private String name;
    private BigDecimal price;
    private Integer stockNum;
    private Integer typeId;

    /*
    * 为了兼容 getGoodsInfo 增加以下字段
    * */
    String desc;
    List<Spec> specs;
    BigDecimal unitPrice;

    /*
    * 为了兼容 getOrderByState，增加以下字段
    * */
    Integer goodsDetailId;
    String spec;


    /**
     * 数据只存储相对路径，为了在前端正常显示需要添加domain，如果让浏览器自动添加，只会拼接前端服务器的ip+端口
     *
     * @param img:
     * @return void
     * @date 11/10/2021 20:21
     */
    private static String domain;

    static {
        Properties properties = new Properties();
        System.out.println("model类加载器：\n"+ GoodsVO.class.getClassLoader());
        try {
            InputStream resourceAsStream = GoodsVO.class.getClassLoader().getResourceAsStream("config/imagedomain.properties");
            properties.load(resourceAsStream);
            domain = properties.getProperty("domain");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void setImg(String img) {
        this.img = domain + img;
    }
}
